// CommandLineHelper Library
// =========================
// License: Microsoft Permissive License (Ms-PL) v1.1
// Author: Rhy Mednick (http://www.rhyverse.net)
// Project Site: http://www.codeplex.com/CommandLineHelper
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using CommandLineHelper.Attributes;

namespace CommandLineHelper.Tests
{
    [TestFixture]
    public class ValidateEnumeratedArgumentsAttribute_Test
    {
        /// <summary>
        ///Verify the IsValid(object) method functions properly
        ///</summary>
        [Test]
        public void IsValid_ValidateEnumeratedArgumentsAttribute()
        {
            ValidateEnumeratedArgumentsAttribute target = new ValidateEnumeratedArgumentsAttribute();

            //verify that we work with correct values
            TestEnum testEnumValue = TestEnum.Zero;
            bool expected = true;
            bool actual;
            actual = target.IsValid(testEnumValue);
            Assert.AreEqual(expected, actual, "[1a]CommandLineHelper.Attributes.ValidateEnumeratedArgumentsAttribute.IsValid did not return the expected value.");

            expected = false;
            actual = true;
            actual = target.IsValid((TestEnum)4); //4 isn't a valid value for the enum
            Assert.AreEqual(expected, actual, "[1b]CommandLineHelper.Attributes.ValidateEnumeratedArgumentsAttribute.IsValid did not return the expected value.");

            TestEnumWithFlags testEnumWithFlagsValue = TestEnumWithFlags.Two;
            expected = true;
            actual = false; //set this to a value different than the expected
            actual = target.IsValid(testEnumWithFlagsValue);
            Assert.AreEqual(expected, actual, "[2a]CommandLineHelper.Attributes.ValidateEnumeratedArgumentsAttribute.IsValid did not return the expected value.");

            //check by using combined values
            testEnumWithFlagsValue = TestEnumWithFlags.Two | TestEnumWithFlags.Four;
            expected = true;
            actual = false;
            actual = target.IsValid(testEnumWithFlagsValue);
            Assert.AreEqual(expected, actual, "[2b]CommandLineHelper.Attributes.ValidateEnumeratedArgumentsAttribute.IsValid did not return the expected value.");
        }

        private enum TestEnum
        {
            Zero = 0,
            One = 1,
            Two = 2,
            Three = 3
        }

        [Flags]
        private enum TestEnumWithFlags
        {
            Zero = 0,
            One = 1,
            Two = 2,
            Four = 4
        }
    }
}
